<template>
	<view class="content">
		<u-navbar
			title="实名认证" 
			:bg-color="`${mainColor}`" 
			fixed 
			placeholder 
			autoBack
			:height="navigationBarHeight"
			:title-style="{color:`${textColor}`, fontSize:'16px', fontWeight:700}"
			:left-icon-color="`${textColor}`"
			v-if="showTitle"
			/>
			
		<view class="content-page">
			<view class="item flex-a" v-for="(item, index) in items" :key="index"
				@click="clickItem(item)">
				<view>
					<image :src="item.icon" class="b-img"></image>
				</view>
				<view class="info">
					{{item.name}}
					<view class="text1">完成{{item.name}}后，{{item.description}}</view>
				</view>
				<image :src="item.mark" class="c-img"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import { systemInfo } from '@/utils/mixin';
	import { getAuthInfo } from '@/api';

	export default {
		mixins: [systemInfo],
		data() {
			return {
				items: []
			}
		},
		onLoad(){
			this.getSystemInfo();
		},
		onShow() {
			this.loadData();
		},
		methods: {
			async loadData() {
				const res = await getAuthInfo();
				this.items = res.data;
				this.items.forEach((item) => {
					item.icon = this.getAuthIcon(item.type);
					item.path = this.getAuthPath(item.type, item.status, item.available);
					item.mark = this.getAuthMarkIcon(item.status);
				})
			},
			clickItem(item) {
				if (!item.path) {
					if (!item.available && item.type == 'advance') {
						uni.showToast({
							title: '请先完成初级认证~',
							icon: 'none'
						})
						return;
					}
					
					if (item.status == 1) {
						uni.showToast({
							title: '正在认证中，请耐心等待~',
							icon: 'none'
						})
						return;
					}
					
					return;
				}
				
				uni.navigateTo({
					url: item.path
				})
			},
			getAuthIcon(type) {
				if (type == 'base') {
					return '/static/authentication1.svg'
				} else if (type == 'advance') {
					return '/static/authentication2.svg'
				}
			},
			getAuthPath(type, status, available) {
				if (!available) return null;
				
				if (status == 1) {
					return null;
				}
				
				if (status == 2) {
					return '/pages/real-name/info';
				}
				
				if (type == 'base') {
					return '/pages/real-name/base';
				} else if (type == 'advance') {
					return '/pages/real-name/advance';
				}
			},
			getAuthMarkIcon(status) {
				if (status == 0) {
					return '/static/authentication.svg'
				} else if (status == 1) {
					return '/static/authentication4.svg'
				} else if (status == 2) {
					return '/static/authentication3.svg'
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

.content-page {
    padding: 10px 10px 0;
	
	.item {
	    position: relative;
	    font-size: 13px;
	    padding: 10px;
	    box-sizing: border-box;
	    margin-bottom: 10px;
	    border-radius: 6px;
	    background-color: #fff;
		
		.b-img {
		    width: 41px;
		    height: 41px;
		    margin-top: 8px;
		    margin-right: 15px;
		}
		
		.text1 {
		    position: relative;
		    z-index: 9;
		    margin-top: 5px;
		    color: #666;
		}
		
		.c-img {
		    position: absolute;
		    top: 10px;
		    right: 10px;
		    width: 41px;
		    height: 17px;
		}
	}
}
</style>
